Skip to content

Kernel API /api/query/sql support || operator #9662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
frostime opened this issue Nov 15, 2023 · 8 comments
Closed
3 tasks done

Kernel API /api/query/sql support || operator #9662

frostime opened this issue Nov 15, 2023 · 8 comments
Assignees
Milestone

Comments

@frostime
Copy link
Contributor

frostime commented Nov 15, 2023

Kernal API SQL 未能查询到预期的结果

Is there an existing issue for this?

  • I have searched the existing issues

Can the issue be reproduced with the default theme (daylight/midnight)?

  • I was able to reproduce the issue with the default theme

Could the issue be due to extensions?

  • I've ruled out the possibility that the extension is causing the problem.

Describe the problem

给定下述 SQL 查询

SELECT * from blocks where
created like strftime('%Y%m%d', 'now') || '%' and type = 'd';

在 Navicat 中连接思源 db,直接结果是正常的:搜索今天所有创建的文档
image


但是在思源中基于后端 API 查询的时候,就无法查询成功

image

image

Query 挂件也是查不到任何东西
image

Expected result

和 Navicat 中的查询保持一致。

Screenshot or screen recording presentation

No response

Version environment

- Version: 2.10.13
- Operating System: win10
- Browser (if used): no

Log file

日志中没有什么有用的信息。

I 2023/11/15 21:54:11 working.go:121: 
      ___                                   ___           ___           ___
     /  /\        ___           ___        /__/\         /  /\         /__/\
    /  /:/_      /  /\         /__/|       \  \:\       /  /::\        \  \:\
   /  /:/ /\    /  /:/        |  |:|        \  \:\     /  /:/\:\        \  \:\
  /  /:/ /::\  /__/::\        |  |:|    ___  \  \:\   /  /:/~/::\   _____\__\:\
 /__/:/ /:/\:\ \__\/\:\__   __|__|:|   /__/\  \__\:\ /__/:/ /:/\:\ /__/::::::::\
 \  \:\/:/~/:/    \  \:\/\ /__/::::\   \  \:\ /  /:/ \  \:\/:/__\/ \  \:\~~\~~\/
  \  \::/ /:/      \__\::/    ~\~~\:\   \  \:\  /:/   \  \::/       \  \:\  ~~~
   \__\/ /:/       /__/:/       \  \:\   \  \:\/:/     \  \:\        \  \:\
     /__/:/        \__\/         \__\/    \  \::/       \  \:\        \  \:\
     \__\/                                 \__\/         \__\/         \__\/
I 2023/11/15 21:54:11 runtime.go:74: kernel is booting:
    * ver [2.10.15]
    * arch [amd64]
    * os [Microsoft Windows 10 Pro]
    * pid [6672]
    * runtime mode [prod]
    * working directory [C:\Users\EEG\AppData\Local\Programs\SiYuan\resources]
    * read only [false]
    * container [std]
    * database [ver=20220501]
    * workspace directory [C:\Users\EEG\Documents\SiYuanNotesMain]
I 2023/11/15 21:54:11 runtime.go:128: use network proxy [system]
I 2023/11/15 21:54:11 serve.go:119: kernel [pid=6672] http server [127.0.0.1:13302] is booting
I 2023/11/15 21:54:12 sync.go:140: sync before boot
I 2023/11/15 21:54:12 ref.go:49: got local latest [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=aad6a4bbe69600965da84a299c794c610d5d2994, created=2023-11-15 21:48:47]
I 2023/11/15 21:54:12 serve.go:132: reverse proxy server [127.0.0.1:6806] is booting
I 2023/11/15 21:54:13 ref.go:49: got local latest [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=aad6a4bbe69600965da84a299c794c610d5d2994, created=2023-11-15 21:48:47]
I 2023/11/15 21:54:13 ref.go:49: got local latest [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=aad6a4bbe69600965da84a299c794c610d5d2994, created=2023-11-15 21:48:47]
I 2023/11/15 21:54:13 siyuan.go:138: downloaded object [siyuan/1646569891270/repo/main/refs/latest]
I 2023/11/15 21:54:13 siyuan.go:138: downloaded object [siyuan/1646569891270/repo/main/indexes/aad6a4bbe69600965da84a299c794c610d5d2994]
I 2023/11/15 21:54:13 sync.go:1483: got cloud latest [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=aad6a4bbe69600965da84a299c794c610d5d2994, created=2023-11-15 21:48:47]
I 2023/11/15 21:54:13 repository.go:1141: boot get sync cloud files elapsed [1.45s]
I 2023/11/15 21:54:13 blocktree.go:494: read block tree [15 MB] to [C:\Users\EEG\Documents\SiYuanNotesMain\temp\blocktree], elapsed [0.12s]
I 2023/11/15 21:54:13 conf.go:726: database size [914 MB], tree/block count [1215/49313]
I 2023/11/15 21:54:13 working.go:159: kernel booted
I 2023/11/15 21:54:14 pandoc.go:132: built-in pandoc [ver=3.1.1, bin=C:\Users\EEG\Documents\SiYuanNotesMain\temp\pandoc\bin\pandoc.exe]
I 2023/11/15 21:54:14 conf.go:948: pandoc initialized, set pandoc bin to [C:\Users\EEG\Documents\SiYuanNotesMain\temp\pandoc\bin\pandoc.exe]
I 2023/11/15 21:54:14 box.go:79: auto stat [trees=1215, blocks=49313, dataSize=1.3 GB, assetsSize=515 MB]
I 2023/11/15 21:54:14 disk.go:33: disk usage [total=240 GB, used=152 GB, free=88 GB]
I 2023/11/15 21:54:59 repository.go:1198: syncing data repo [device=fb052697-1d9d-43f2-a74e-69b03a7027f9, kernel=gn4xrne, provider=0, mode=a/false]
I 2023/11/15 21:54:59 ref.go:49: got local latest [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=aad6a4bbe69600965da84a299c794c610d5d2994, created=2023-11-15 21:48:47]
I 2023/11/15 21:54:59 ref.go:49: got local latest [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=aad6a4bbe69600965da84a299c794c610d5d2994, created=2023-11-15 21:48:47]
I 2023/11/15 21:54:59 ref.go:63: updated local latest to [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=e98f8eb27d35e3b15556c5edbafae5126ed20b08, created=2023-11-15 21:54:59]
I 2023/11/15 21:55:00 siyuan.go:112: uploaded object [siyuan/1646569891270/repo/main/lock-sync]
I 2023/11/15 21:55:00 ref.go:49: got local latest [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=e98f8eb27d35e3b15556c5edbafae5126ed20b08, created=2023-11-15 21:54:59]
I 2023/11/15 21:55:00 siyuan.go:138: downloaded object [siyuan/1646569891270/repo/main/refs/latest]
I 2023/11/15 21:55:00 siyuan.go:138: downloaded object [siyuan/1646569891270/repo/main/indexes/aad6a4bbe69600965da84a299c794c610d5d2994]
I 2023/11/15 21:55:00 sync.go:1483: got cloud latest [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=aad6a4bbe69600965da84a299c794c610d5d2994, created=2023-11-15 21:48:47]
I 2023/11/15 21:55:00 sync.go:1242: upsert file [a45594206f489d85b2b6585718c5dfd85b268928, /20220305173526-4yjl33h/20220316145830-u0u6srg/20230101002839-etqg573/20231101094918-4mut421/20231115093618-aworzvg.sy, 2023-11-15 21:54:24] chunk [d9ca79a92cc098098f34000a965c44c31c5b2952]
I 2023/11/15 21:55:00 sync.go:1242: upsert file [dcd59615759e3cc36e2fd12530f4d15903d3c8f0, /storage/petal/siyuan-dailynote-today/Reservation.json, 2023-11-15 21:54:16] chunk [feaf9b83221f4f96c497be7337e6453171c2a07e]
I 2023/11/15 21:55:00 sync.go:1242: upsert file [f6f7ee63f1c44aab99eeab28d74639cc96e5c1f5, /storage/petal/siyuan-dailynote-today/DailyNoteToday.json.txt, 2023-11-15 21:54:17] chunk [81802ae1299a90bd1d5e8762aed0e93c87c5b785]
I 2023/11/15 21:55:00 sync.go:1258: upsert chunk [d9ca79a92cc098098f34000a965c44c31c5b2952]
I 2023/11/15 21:55:00 siyuan.go:112: uploaded object [siyuan/1646569891270/repo/main/objects/d9/ca79a92cc098098f34000a965c44c31c5b2952]
I 2023/11/15 21:55:00 sync.go:1178: uploaded chunk [objects/d9/ca79a92cc098098f34000a965c44c31c5b2952, 1/1]
I 2023/11/15 21:55:00 siyuan.go:112: uploaded object [siyuan/1646569891270/repo/main/objects/f6/f7ee63f1c44aab99eeab28d74639cc96e5c1f5]
I 2023/11/15 21:55:00 sync.go:1125: uploaded file [objects/f6/f7ee63f1c44aab99eeab28d74639cc96e5c1f5, 1/3]
I 2023/11/15 21:55:00 siyuan.go:112: uploaded object [siyuan/1646569891270/repo/main/objects/a4/5594206f489d85b2b6585718c5dfd85b268928]
I 2023/11/15 21:55:00 sync.go:1125: uploaded file [objects/a4/5594206f489d85b2b6585718c5dfd85b268928, 2/3]
I 2023/11/15 21:55:00 siyuan.go:112: uploaded object [siyuan/1646569891270/repo/main/objects/dc/d59615759e3cc36e2fd12530f4d15903d3c8f0]
I 2023/11/15 21:55:00 sync.go:1125: uploaded file [objects/dc/d59615759e3cc36e2fd12530f4d15903d3c8f0, 3/3]
I 2023/11/15 21:55:00 sync.go:1371: got latest sync [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=aad6a4bbe69600965da84a299c794c610d5d2994, created=2023-11-15 21:48:47]
I 2023/11/15 21:55:00 diff.go:49: upsert [lID=aeaa7db6a7a06f1497a072496a94a21cfd9c3858, lPath=/20220305173526-4yjl33h/20220316145830-u0u6srg/20230101002839-etqg573/20231101094918-4mut421/20231115093618-aworzvg.sy, lUpdated=2023-11-15 21:48:15, rID=a45594206f489d85b2b6585718c5dfd85b268928, rPath=/20220305173526-4yjl33h/20220316145830-u0u6srg/20230101002839-etqg573/20231101094918-4mut421/20231115093618-aworzvg.sy, rUpdated=2023-11-15 21:54:24]
W 2023/11/15 21:55:00 diff.go:56: prevent old upsert left [aeaa7db6a7a06f1497a072496a94a21cfd9c3858, /20220305173526-4yjl33h/20220316145830-u0u6srg/20230101002839-etqg573/20231101094918-4mut421/20231115093618-aworzvg.sy, 2023-11-15 21:48:15] overwrite right [a45594206f489d85b2b6585718c5dfd85b268928, /20220305173526-4yjl33h/20220316145830-u0u6srg/20230101002839-etqg573/20231101094918-4mut421/20231115093618-aworzvg.sy, 2023-11-15 21:54:24]
I 2023/11/15 21:55:00 diff.go:49: upsert [lID=76ce8871ff6ba2a8e2347bb7e672c4ba0d5d3f1c, lPath=/storage/petal/siyuan-dailynote-today/DailyNoteToday.json.txt, lUpdated=2023-11-15 20:05:11, rID=f6f7ee63f1c44aab99eeab28d74639cc96e5c1f5, rPath=/storage/petal/siyuan-dailynote-today/DailyNoteToday.json.txt, rUpdated=2023-11-15 21:54:17]
W 2023/11/15 21:55:00 diff.go:56: prevent old upsert left [76ce8871ff6ba2a8e2347bb7e672c4ba0d5d3f1c, /storage/petal/siyuan-dailynote-today/DailyNoteToday.json.txt, 2023-11-15 20:05:11] overwrite right [f6f7ee63f1c44aab99eeab28d74639cc96e5c1f5, /storage/petal/siyuan-dailynote-today/DailyNoteToday.json.txt, 2023-11-15 21:54:17]
I 2023/11/15 21:55:00 diff.go:49: upsert [lID=174684f12725454345eec07165f21eeaddd75379, lPath=/storage/petal/siyuan-dailynote-today/Reservation.json, lUpdated=2023-11-15 20:05:11, rID=dcd59615759e3cc36e2fd12530f4d15903d3c8f0, rPath=/storage/petal/siyuan-dailynote-today/Reservation.json, rUpdated=2023-11-15 21:54:16]
W 2023/11/15 21:55:00 diff.go:56: prevent old upsert left [174684f12725454345eec07165f21eeaddd75379, /storage/petal/siyuan-dailynote-today/Reservation.json, 2023-11-15 20:05:11] overwrite right [dcd59615759e3cc36e2fd12530f4d15903d3c8f0, /storage/petal/siyuan-dailynote-today/Reservation.json, 2023-11-15 21:54:16]
I 2023/11/15 21:55:00 sync.go:240: local upsert [f6f7ee63f1c44aab99eeab28d74639cc96e5c1f5, /storage/petal/siyuan-dailynote-today/DailyNoteToday.json.txt, 2023-11-15 21:54:17]
I 2023/11/15 21:55:00 sync.go:240: local upsert [dcd59615759e3cc36e2fd12530f4d15903d3c8f0, /storage/petal/siyuan-dailynote-today/Reservation.json, 2023-11-15 21:54:16]
I 2023/11/15 21:55:00 sync.go:240: local upsert [a45594206f489d85b2b6585718c5dfd85b268928, /20220305173526-4yjl33h/20220316145830-u0u6srg/20230101002839-etqg573/20231101094918-4mut421/20231115093618-aworzvg.sy, 2023-11-15 21:54:24]
I 2023/11/15 21:55:01 siyuan.go:138: downloaded object [siyuan/1646569891270/repo/main/indexes-v2.json]
I 2023/11/15 21:55:01 siyuan.go:112: uploaded object [siyuan/1646569891270/repo/main/indexes/e98f8eb27d35e3b15556c5edbafae5126ed20b08]
I 2023/11/15 21:55:01 sync.go:1091: uploaded index [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=e98f8eb27d35e3b15556c5edbafae5126ed20b08, created=2023-11-15 21:54:59]
I 2023/11/15 21:55:01 siyuan.go:112: uploaded object [siyuan/1646569891270/repo/main/refs/latest]
I 2023/11/15 21:55:01 siyuan.go:112: uploaded object [siyuan/1646569891270/repo/main/check/indexes/982176257b08bf1fbea8a3c1c7802fb149947ffe]
I 2023/11/15 21:55:01 siyuan.go:112: uploaded object [siyuan/1646569891270/repo/main/indexes-v2.json]
I 2023/11/15 21:55:01 siyuan.go:138: downloaded object [siyuan/1646569891270/repo/main/refs/latest]
I 2023/11/15 21:55:01 sync.go:1299: updated latest sync [device=fb052697-1d9d-43f2-a74e-69b03a7027f9/windows, id=e98f8eb27d35e3b15556c5edbafae5126ed20b08, created=2023-11-15 21:54:59]
I 2023/11/15 21:55:01 siyuan.go:173: removed object [siyuan/1646569891270/repo/main/lock-sync]
I 2023/11/15 21:55:01 repository.go:1254: synced data repo [device=fb052697-1d9d-43f2-a74e-69b03a7027f9, kernel=gn4xrne, provider=0, mode=a/false, ufc=6, dfc=2, ucc=1, dcc=0, ub=286 kB, db=407 kB] in [2.56s], merge result [conflicts=0, upserts=0, removes=0]


More information

No response

@frostime frostime changed the title Kernal API SQL 的查询异常 Kernal API SQL 未能查询到预期的结果 Nov 15, 2023
@zxhd863943427
Copy link
Contributor

一个更简单的示例:

SELECT * from blocks where created like "20231115" || "%"

似乎是字符串连接出错了

@zxhd863943427
Copy link
Contributor

一个更简单的示例:

SELECT  memo from blocks where memo like "2023111" || "5"

这必然会查到无意义的结果,而无需你真的在 memo 填写 20231115

@88250 88250 self-assigned this Nov 15, 2023
@88250 88250 added this to the 2.10.16 milestone Nov 15, 2023
@88250 88250 changed the title Kernal API SQL 未能查询到预期的结果 Improve kernel API /api/query/sql parsing Nov 15, 2023
@88250 88250 changed the title Improve kernel API /api/query/sql parsing Kernel API /api/query/sql support || operator Nov 15, 2023
@88250 88250 closed this as completed Nov 15, 2023
@frostime
Copy link
Contributor Author

frostime commented Nov 15, 2023

等一下老哥,这个意思是更新之后 union 反而不能用了吗 😂

image


哦,好像理解有误。意思是根据是否有 '||' 选择不同的解析器是吧。。

@88250
Copy link
Member

88250 commented Nov 15, 2023

能用的,只是不带 LIMIT 的话性能会比原来差(原来是预加 LIMIT,现在是查询后结果集中 LIMIT)。

@winter60
Copy link

似乎 limit 语句不能单独换行,否则对查询结果有影响。 @88250

@88250
Copy link
Member

88250 commented Nov 17, 2023 via email

@winter60
Copy link

winter60 commented Nov 17, 2023 via email

@88250
Copy link
Member

88250 commented Nov 17, 2023

这个语句两个解析器都无法正常解析,所以走了内置原生的执行,但是我看了下,执行结果应该是对的:

image

88250 added a commit that referenced this issue Nov 17, 2023

Verified

This commit was signed with the committer’s verified signature.
stevendanna Steven Danna
88250 added a commit that referenced this issue Nov 17, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants